<template>
  <GlobalMask v-if="showMask" @close="showMask = false" />
  <router-view />
</template>

<script setup>
import { ref, watch } from "vue";
import { useRoute } from "vue-router";
import GlobalMask from "@/components/GlobalMask.vue";

const showMask = ref(false);
const route = useRoute();

watch(
  () => route.fullPath,
  (newPath, oldPath) => {
    // 只有从登录页跳转到主页面时才弹出
    console.log(oldPath, newPath, sessionStorage.getItem("maskShown"));

    if (
      oldPath &&
      oldPath.startsWith &&
      oldPath.startsWith("/login") &&
      !newPath.startsWith("/login") &&
      sessionStorage.getItem("maskShown") !== "1"
    ) {
      showMask.value = true;
      sessionStorage.setItem("maskShown", "1");
    }
  },
  { immediate: true }
);
</script>
